add_custom_target (create_tests_source python ${CMAKE_CURRENT_SOURCE_DIR}/create_tests_source.py 44100Hz_44100f_sine441_stereo.wav)

function (aubio_add_test source)
  # create name
  string (REGEX REPLACE ".*/\([a-z_-]+\).c$" "\\1" name "${source}")
  add_executable (${name} "${source}")
  add_test (NAME ${name} COMMAND ${name})

  target_link_libraries (${name} PUBLIC aubio)
  #target_link_libraries (${name} PRIVATE progutils)
  target_include_directories (${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
  target_include_directories (${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src)
  target_include_directories (${name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src)

  target_compile_definitions (${name} PRIVATE AUBIO_TESTS_SOURCE=${CMAKE_CURRENT_BINARY_DIR}/44100Hz_44100f_sine441_stereo.wav)
  target_compile_definitions (${name} PRIVATE AUBIO_UNSTABLE_API=1)

  add_dependencies (${name} create_tests_source)

endfunction ()

aubio_add_test (src/test-fvec.c)
aubio_add_test (src/test-lvec.c)
aubio_add_test (src/test-cvec.c)
aubio_add_test (src/test-fmat.c)
aubio_add_test (src/test-mathutils-window.c)
aubio_add_test (src/test-mathutils.c)
aubio_add_test (src/test-vecutils.c)
aubio_add_test (src/utils/test-hist.c)
aubio_add_test (src/utils/test-log.c)
aubio_add_test (src/utils/test-parameter.c)
aubio_add_test (src/utils/test-scale.c)
aubio_add_test (src/temporal/test-a_weighting.c)
aubio_add_test (src/temporal/test-biquad.c)
aubio_add_test (src/temporal/test-c_weighting.c)
aubio_add_test (src/temporal/test-filter.c)
aubio_add_test (src/temporal/test-resampler.c)
aubio_add_test (src/spectral/test-awhitening.c)
aubio_add_test (src/spectral/test-dct.c)
aubio_add_test (src/spectral/test-fft.c)
aubio_add_test (src/spectral/test-filterbank.c)
aubio_add_test (src/spectral/test-filterbank_mel.c)
aubio_add_test (src/spectral/test-mfcc.c)
aubio_add_test (src/spectral/test-phasevoc.c)
aubio_add_test (src/spectral/test-specdesc.c)
aubio_add_test (src/spectral/test-tss.c)
aubio_add_test (src/effects/test-pitchshift.c)
aubio_add_test (src/effects/test-timestretch.c)
if (RUBBERBAND_FOUND)
  # FIXME should be removed but used in tests
  target_compile_definitions (test-pitchshift PUBLIC HAVE_RUBBERBAND)
  target_compile_definitions (test-timestretch PUBLIC HAVE_RUBBERBAND)
endif ()
aubio_add_test (src/io/test-sink.c)
aubio_add_test (src/io/test-sink_apple_audio.c)
aubio_add_test (src/io/test-sink_flac.c)
aubio_add_test (src/io/test-sink_sndfile.c)
aubio_add_test (src/io/test-sink_vorbis.c)
aubio_add_test (src/io/test-sink_wavwrite.c)
aubio_add_test (src/io/test-source.c)
aubio_add_test (src/io/test-source_apple_audio.c)
aubio_add_test (src/io/test-source_avcodec.c)
aubio_add_test (src/io/test-source_sndfile.c)
aubio_add_test (src/io/test-source_wavread.c)
aubio_add_test (src/notes/test-notes.c)
aubio_add_test (src/onset/test-onset.c)
aubio_add_test (src/onset/test-peakpicker.c)
aubio_add_test (src/pitch/test-pitch.c)
aubio_add_test (src/pitch/test-pitchfcomb.c)
aubio_add_test (src/pitch/test-pitchmcomb.c)
aubio_add_test (src/pitch/test-pitchschmitt.c)
aubio_add_test (src/pitch/test-pitchspecacf.c)
aubio_add_test (src/pitch/test-pitchyin.c)
aubio_add_test (src/pitch/test-pitchyinfft.c)
aubio_add_test (src/synth/test-sampler.c)
aubio_add_test (src/synth/test-wavetable.c)
aubio_add_test (src/tempo/test-beattracking.c)
aubio_add_test (src/tempo/test-tempo.c)
